以及一些测试程序代码等 2 编译生成.NET库(DLL)和Java库(Jar) 解压thrift-0.9.3.tar.g
8899);TProtocolprotocol = new TBinaryProtocol(transport);test.Hello.Client client = newtest.Hello.Client(protocol);transport.Open();Console.WriteLine(Client calls client.helloString().....);Console.WriteLine(client.helloString(jiyiqin));client.Dispose();}}} 7 运行 运行java处事端Server.java: thrift server init thrift server start thrift server host on port 8899 get jiyiqin 1 运行C#客户端代码ClientTest.cs Client calls client.helloString()..... Hello jiyiqin 1 请按任意键继承 可以看到Thrift和ICE等跨语言RPC框架开拓步调很是相似,险些沟通, (1) 生成.NET库 打开工程:E:Thrift hrift-0.9.3libcsharpsrcThrift.sln 编译。
即可生成Thrift.dll 我的情况是VS2010以及.NET 4.0 (2) 生成Java库 Java库是通过Ant构建的,需要安装Ant, using System;using System.Collections.Generic;using System.Linq;using System.Text;using Thrift.Transport;using Thrift.Protocol;namespace ThriftTest{class ClientTest{static void Main(string[]args){TTransporttransport = new TSocket(localhost,安装步调这里就不赘述了,转载请注明出处:jiq钦s technical BlogApache Thrift 是 Facebook 实现的一种高效的、支持多种IT之家语言的长途处事挪用的框架,可是和基于Servlet的Hessian这种跨语言RPC框架不同较大,以及一些测试措施代码等 2 编译生成.NET库(DLL)和Java库(Jar) 解压thrift-0.9.3.tar.gz文件。
true);Args args = newArgs(serverTransport);args.processor(process);args.protocolFactory(portFactory);TServer server = newTThreadPoolServer(args);server.serve();} catch (TTransportException e) {e.printStackTrace();}}publicstaticvoidmain(String[] args) {System.out.println(thrift server init);Server server = new Server();System.out.println(thrift server start);server.startServer();System.out.println(thrift server end);} } 6 编写C#客户端代码 新建普通节制台项目, 1 下载Thrift 下载地点: thrift-0.9.3.exe 用于编译Thrift中间文件生成对应语言代码的东西 thrift-0.9.3.tar.gz 包括Thrift各个语言的源码库。
引入Thrift.dll;然后还要将生成的Hello.cs也插手到工程中, 打开呼吁行CD到java库代码地址的路径:E:Thrift hrift-0.9.3libjava(包括build.xml) 然后直接执行ant呼吁即可发明build目次下生成对应的jar文件,雷同的跨语言RPC框架尚有ICE、Hessian、Protocol Buffer、Avro等。
5 编写Java处事端代码 新建普通Java项目, 3 编写thrift中间文件namespace java testnamespace csharp testservice Hello {string helloString(1:string word)}4 生成Java和C#各自的接口文件 Thrift-0.9.3.exe gen java test.thrift Thrift-0.9.3.exe gen csharp test.thrift 可以看到在当前目次下会呈现生成的对应代码,留意包名, ,启动并监听在指定端口: package test;import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TBinaryProtocol.Factory; import org.apache.thrift.server.TServer; import org.apache.thrift.server.TThreadPoolServer; import org.apache.thrift.server.TThreadPoolServer.Args; import org.apache.thrift.transport.TServerSocket; import org.apache.thrift.transport.TTransportException; import test.Hello.Processor; public classServer {@SuppressWarnings({rawtypes,生成的文件也都差不多, (1)首先编写接话柄现类: package test;import org.apache.thrift.TException;import test.Hello.Iface; public classHelloImpl implementsIface{privatestaticintcount= 0;@OverridepublicString helloString(String word)throwsTException {count += 1;System.out.println(get + word + +count);return hello + word + + count;} } (2)编写投止代码, unchecked })public void startServer() {try {System.out.println(thrift server host on port 8899);TServerSocket serverTransport = new TServerSocket(8899);Hello.Processorprocess = newProcessor(newHelloImpl());Factory portFactory = newTBinaryProtocol.Factory(true,将之前ant编译生成的相关的jar文件(libthrift-0.9.3.jar以及E:Thrift hrift-0.9.3libjavauildlib目次下所有jar文件)add tobuild path;然后还要将生成的Hello.java也插手到工程中,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/net/13000.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
PS:这里需要注意
时间:2021-01-22
-
以为这个版本出来
时间:2021-01-22
-
搜索winform designer
时间:2021-01-22
-
全新的membership框架Asp.ne
时间:2021-01-21
-
i dont know;18if (msg.Contains(
时间:2021-01-21
-
统筹管理路由规则.
时间:2021-01-21
-
根据switch-case语句来逐一判
时间:2021-01-21
-
EntityFramework 5.0 CodeFirst 教
时间:2021-01-21
热门文章
-
.NET 开发环境搭建图文详解
时间:2020-12-27
-
Windows下Visual Studio 2017安装配置方法图文教
时间:2020-12-23
-
PS: 如果项目中使用了通用主机或者ASP.
时间:2021-01-12
-
.Net微信网页开发解决用户在不同公众号或
时间:2021-01-03
-
oracle 11g rac安装之grid报错解决
时间:2020-12-28
-
以为这个版本出来
时间:2021-01-22
-
ASP.NET Core 3.0使用gRPC的具体方法
时间:2020-12-26
-
SpringBoot实战之文件上传存入AzureStorage
时间:2020-12-29
-
不用找了,比较全的signalR例子已经为你准
时间:2020-12-29
-
.NET Core3.1编写混合C++程序
时间:2020-12-26
